/* eslint-disable eol-last */
/* eslint-disable indent */
'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
    async index() {
        const { ctx } = this;
        // session 中获取个人信息
        const userInfo = ctx.session.getUserInfo;
        // 获取粉丝列表
        // console.log(ctx.session);
        const { userList: fansList, count: fansCount } = await this.service.userRelation.getUsersByFollowerId(userInfo.id);

        // 获取关注列表
        const { userList: followList, count: followCount } = await this.service.userRelation.getFollower(userInfo.id);
        //  获取关注人博客列表
        const result = await this.service.blog.getFollowerBlogList({ userId: userInfo.id, pageIndex: 0, pageSize: 10 });
        const { count, blogList } = result;

        // 获取@ 我的数量
        const atCount = await this.service.atRelation.getAtCount(userInfo.id);
        await ctx.render('index.html', {
            // title:'盛邦微博',
            isNav: true,
            userData: {
                userInfo,
                fansData: { // 粉丝
                    count: fansCount,
                    fansList,
                },
                followData: { // 关注
                    count: followCount,
                    followList,
                },
                isMe: true,
                atCount,
            },
            blogList,
            count,
            pageIndex: 1,
            pageSize: 10,
        });
    }


    async settingPage() {
            const { userName } = this.ctx.params;
            this.ctx.body = {
                userName,
            };
        }
        // 加载更多
    async loadingMore() {
            const { userName, pageIndex } = this.ctx.params;
            this.ctx.body = {
                mag: '加载更多',
                userName,
                pageIndex,
            };
        }
        // 404页面
    async notFound() {
        await this.ctx.render('404.html', { isNav: true });
    }

}


module.exports = HomeController;